/*
 * @Author: zjj
 * @Date: 2019-11-06 09:36:59
 * @LastEditors: zjj
 * @LastEditTime: 2019-12-11 09:22:58
 */
var myMixin = {
    data() {
        return {
            isRequest:false,//是否在请求
            isRefesh: false,//下拉刷新
            last_page: 1,//最后一页
            current_page: 0,//当前页
            loading: false//是否加载
        }
    },
    computed: {
        noMore() {
            return this.last_page == this.current_page;
        },
        disabled() {
            return this.loading || this.noMore;
        }
    },
    methods: {
        noMoreData() {
            return this.last_page != this.current_page;
        },
        execResult(res){
            if (res.data.result && res.data.result.length != 0) {
                this.productList = [...this.productList, ...res.data.result,];
                this.current_page += 1;
                this.last_page = this.current_page + 1;
              } else {
                this.last_page = this.current_page;
              }
              return this.productList
        },
        isScrollEnd(element){
            //变量scrollTop是滚动条滚动时，距离顶部的距离
            var scrollTop =element.scrollTop
            //   document.documentElement.scrollTop || document.body.scrollTop;
            //变量windowHeight是可视区的高度
            var windowHeight =element.clientHeight
            //   document.documentElement.clientHeight || document.body.clientHeight;
            //变量scrollHeight是滚动条的总高度
            var scrollHeight =element.scrollHeight
            //   document.documentElement.scrollHeight || document.body.scrollHeight;
            //滚动条到底部的条件
              if (scrollTop + windowHeight >= (scrollHeight*0.8) && scrollTop != 0) {
                return true
              }
              return false
           
        },
        //加载更多
        // 加载更多
        scrollToEnd() {
            if (this.noMore) {
                return;
            }
            this.loading = true;
            this._api()
        },
        pageToEnd() {
            if (this.noMore) {
                return;
            }
            this.loading = true;
            this._api()
        }

    }
}

export default myMixin